//
//  OMSalesRankCollectCell.m
//  OMENGO_NEW
//
//  Created by 梁尚嘉 on 2017/5/19.
//  Copyright © 2017年 Kamfat. All rights reserved.
//

#import "OMSalesRankCollectCell.h"
#import "OMProduct.h"
#import "OMSalesNumberView.h"
@interface OMSalesRankCollectCell()
@property (nonatomic, strong) OMSalesNumberView *salesView;
@end
@implementation OMSalesRankCollectCell
- (void)configureCellWithObj:(OMProduct *)good
{
    [super configureCellWithObj:good];

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSMutableAttributedString *title = [[NSMutableAttributedString alloc]initWithString: good.brand?:@"" attributes:@{NSFontAttributeName:SM_CBFont(30)}];
        !title.string.length?:[title appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
        [title appendAttributedString:[[NSAttributedString alloc] initWithString:good.name?:@"" attributes:@{NSFontAttributeName:SM_CFont(30)}]];

        dispatch_async(dispatch_get_main_queue(), ^{
            self.brandLabel.attributedText = title;
        });
    });
    self.salesView.num = good.sales;
    self.salesView.hidden = !good.sales;
}

- (void)configure
{
    [super configure];
    [self.iconImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(SM_SIZE(20)));
        make.top.equalTo(@(SM_SIZE(10)));
        make.bottom.equalTo(@(SM_SIZE(-10)));
        make.width.equalTo(self.iconImageView.mas_height);
    }];

    self.brandLabel.textColor = SM_darkGrayColor;
    [self.brandLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconImageView.mas_right).offset(SM_SIZE(25));
        make.top.equalTo(self.iconImageView.mas_top).offset(SM_SIZE(20));
        make.right.equalTo(@(SM_SIZE(-15)));
    }];

    self.specLabel.font = SM_CFont(26);
    [self.specLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.brandLabel.mas_left);
        make.top.equalTo(self.brandLabel.mas_bottom).offset(SM_SIZE(15));
    }];

    _salesView = [OMSalesNumberView new];
    [self.contentView addSubview:_salesView];
    [_salesView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.brandLabel.mas_left);
        make.bottom.equalTo(self.iconImageView.mas_bottom).offset(SM_SIZE(-10));
    }];

    self.priceLabel.font = SM_NFont(40);
    self.priceLabel.textColor = SM_blackColor;
    [self.priceLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.brandLabel.mas_left);
        make.bottom.equalTo(_salesView.mas_top).offset(SM_SIZE(-10));
    }];

    [self.basketButton mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(SM_SIZE(-30)));
        make.width.height.equalTo(@(SM_SIZE(70)));
        make.centerY.equalTo(self.salesView.mas_centerY);
    }];

}
@end
